#ifndef __TYPEDEF_H
#define __TYPEDEF_H


#define PUBLIC 
#define LOCAL static

typedef _Bool          bool;

typedef unsigned char	u8_t;
typedef signed char    	s8_t;

typedef unsigned short 	u16_t;
typedef signed short   	s16_t;

typedef unsigned long  	u32_t;
typedef signed long    	s32_t;

typedef unsigned long  	u64_t;
typedef signed long    	s64_t;

typedef enum {LOW = 0, HIGH = !LOW} FlagStatus, ITStatus, BitStatus, BitAction;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;

#define TRUE   	1
#define FALSE  	0
#define true   		1
#define false  		0
#define NULL   	0

#define P_REG8(addr)		((volatile u8_t __xdata*)addr)
#define REG8(addr)                 (*P_REG8(addr))
#define REG8_READ(addr)            REG8(addr)
#define REG8_WRITE(addr,byte)      REG8(addr) = byte

#define REGS16(addr)                 (*((volatile s16_t __xdata*)addr))

#define REG16(addr)                 (*((volatile u16_t __xdata*)addr))
#define REG16_READ(addr)            REG16(addr)         //xsfr_word_read(addr)
#define REG16_WRITE(addr,word)      REG16(addr) = word                //{REG8(addr) = word&0xFF; REG8(addr+1) = (word>>8);}

#define REG32(addr)                 (*((volatile u32_t __xdata*)addr))
#define XDATA32(addr)               (*((u32_t __xdata*)addr))
#define REG32_READ(addr)            REG32(addr)               //REG32(addr)
#define REG32_WRITE(addr,dword)    REG32(addr) = dword        //{REG8(addr) = word&0xFF; REG8(addr+1) = (word>>8); REG8(addr+2) = (word>>16); REG8(addr+3) = (word>>24);}

#define BIT(n)                  (1<<n)
#define BitSet(ADDR,POS)         (REG8(ADDR) |= (BIT(POS)))
#define BitClr(ADDR,POS)         (REG8(ADDR) &= (~(BIT(POS))))
#define BitChg(VAR,POS)         (VAR ^= ((1 << POS)))
#define BitCHK_1(VAR,POS)       ((VAR & (1 << POS)) == (1 << POS))
#define BitCHK_0(VAR,POS)       ((VAR & (1 << POS)) == 0x00)

#endif
